from models import LoginzaUser

SESSION_USER_VARNAME = '_loginzauth_user_pk'

class AuthMiddleware:
    def process_request(self, request):
        try:
            pk = request.session.get(SESSION_USER_VARNAME)
            user = LoginzaUser.objects.get(pk=pk)
        except LoginzaUser.DoesNotExist:
            user = None
        request.loginzauth_user = user
